<!--河南星辰软件科技有限公司
@copyright Copyright (c) 2010~2022 All rights reserved.
-->
<template>
  <div class='app-container'>
    <el-row>
      <el-col :span='22' :xs='24'>
        <el-form ref="form" :model="t_device" :rules="rules" label-width="100px" id="mvcfm">
          <div class="form-unit">
            <span class="mvc-title-left"> 设备名称 </span>
          </div>
          <div>
            <el-row>
              <el-col :span="24">
                <el-form-item label="定义设备名称" prop="">
                  {{t_device.define_name}}
                </el-form-item>
              </el-col>
            </el-row>
          </div>
          <el-button @click="popDeviceRelation('&category_id=')" type='primary' size="mini">添加关联设备</el-button>
          <div class="form-unit">
            <span class="mvc-title-left"> 关联设备 </span>
          </div>
          <el-table :data="s_relat">
            <el-table-column label="操作" align="center" width='100' type=''>
              <template slot-scope="scope">
                <el-dropdown trigger="click">
                  <span class="el-dropdown-link">操作<i class="el-icon-arrow-down el-icon--right"></i></span>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item>
                      <el-link @click="d_relat('&CMID4='+scope.row.relat_id+'')">删除</el-link>
                    </el-dropdown-item>
                    <el-dropdown-item>
                      <el-link @click="gotoPage(''+vueparams+'')">上移</el-link>
                    </el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
              </template>
            </el-table-column>
            <el-table-column label="关联设备条形码" prop="produce_barcode">
            </el-table-column>
            <el-table-column label="关联设备名称" prop="produce_name">
            </el-table-column>
            <el-table-column label="关联设备型号" prop="produce_model">
            </el-table-column>
            <el-table-column label="关联设备规格" prop="produce_norm">
            </el-table-column>
          </el-table>
        </el-form>
      </el-col>
      <el-col :span='2' :xs='24'>
        <el-menu default-active='active' class='menu-unit'>
          <el-menu-item v-for='item in Container'>
            <el-link @click="gotoMenu(item.url)" :type="'成套关联'===item.name?'primary':'default'">{{item.page_desc||item.name}}</el-link>
          </el-menu-item>
        </el-menu>
      </el-col>
    </el-row>
    <el-dialog :visible.sync="DeviceRelationVisible" append-to-body>
      <DeviceRelation v-if="DeviceRelationVisible" ref="DeviceRelation" :popparams="popparams"> </DeviceRelation>
    </el-dialog>
  </div>
</template>
<script>
  import request from '@/utils/request'
  import DeviceRelation from "@/views/mes/produce/DeviceRelation";
  export default {
    name: 'Complete',
    components: {
      DeviceRelation,
    },
    props: ['popparams'],
    data() {
      return {
        DeviceRelationVisible: false,
        DeviceRelationValue: null,
        DeviceRelationDesc: null,
        vueparams: this.getVUEParams(""),
        t_device: {
          define_name: null,
        },
        s_relat: [],
        loading: false,
        Container: null,
        rules: {}
      }
    },
    created() {
      this.getData();
      this.loadContainerMenu({
        pid: "D797D94B97264F339A7F3838BB343F64",
        name: "生产设备右菜单",
        selected: "成套关联"
      }, 'Container', this.vueparams);
    },
    updated() {},
    mounted() {},
    methods: {
      getData() {
        request({
          method: 'get',
          url: '/xcapi/VUEAction/mes/produce/HolderTool/complete?' + this.vueparams,
        }).then(data => {
          for (var k in data) {
            if (Array.isArray(data[k])) {
              this[k] = data[k];
            } else {
              $.extend(this[k], data[k]);
            }
          }
        })
      },
      d_relat(_params) {
        request({
          method: 'post',
          url: '/xcapi/VUEAction/mes/produce/HolderTool/d_relat?' + _params + this.vueparams,
          data: this.postData()
        }).then(data => {
          this.$router.replace("/redirect" + this.$route.fullPath);
          this.msgSuccess(data.msg);
        })
      },
      popDeviceRelation(params) {
        if (params != "") this.popparams = params + this.vueparams;
        this.DeviceRelationVisible = !this.DeviceRelationVisible;
      },
    },
  }
</script>
